package com.xyht.sca_s.student_manage_system.modules.chargePayment.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wechat.pay.java.service.partnerpayments.jsapi.model.PrepayWithRequestPaymentResponse;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonCodeEnum;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ExceptionCast;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.util.OrgUserStuUtil;
import com.xyht.sca_s.student_manage_system.common.util.TimeUtil;
import com.xyht.sca_s.student_manage_system.modules.advanceRegistration.entity.RxAdvanceRegistrationStudentInfo;
import com.xyht.sca_s.student_manage_system.modules.advanceRegistration.mapper.RxAdvanceRegistrationStudentInfoMapper;
import com.xyht.sca_s.student_manage_system.modules.chargePayment.entity.SmsWnsChargePaymentCategoryDivide;
import com.xyht.sca_s.student_manage_system.modules.chargePayment.entity.SmsWnsChargePaymentRecord;
import com.xyht.sca_s.student_manage_system.modules.chargePayment.entity.req.PaymentCategoryDivideReq;
import com.xyht.sca_s.student_manage_system.modules.chargePayment.entity.req.SmsWnsChargePaymentRecordReq;
import com.xyht.sca_s.student_manage_system.modules.chargePayment.entity.resp.*;
import com.xyht.sca_s.student_manage_system.modules.chargePayment.mapper.SmsWnsChargePaymentCategoryDivideMapper;
import com.xyht.sca_s.student_manage_system.modules.chargePayment.mapper.SmsWnsChargePaymentRecordMapper;
import com.xyht.sca_s.student_manage_system.modules.chargePayment.service.SmsWnsChargePaymentRecordService;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.entity.SmsEnrollmentManagementStudentInfo;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.mapper.SmsEnrollmentManagementStudentInfoMapper;
import com.xyht.sca_s.student_manage_system.modules.payment.wxpay.config.WxPayConfig;
import com.xyht.sca_s.student_manage_system.modules.payment.wxpay.entity.PrepayPaymentReq;
import com.xyht.sca_s.student_manage_system.modules.payment.wxpay.entity.WxPayFunctions;
import com.xyht.sca_s.student_manage_system.modules.payment.wxpay.util.WxPayUtil;
import com.xyht.sca_s.student_manage_system.modules.student.entity.SmsStudentInfo;
import com.xyht.sca_s.student_manage_system.modules.student.entity.SmsUserStudentRelation;
import com.xyht.sca_s.student_manage_system.modules.student.entity.resp.SmsStudentInfoResp;
import com.xyht.sca_s.student_manage_system.modules.student.mapper.SmsStudentInfoMapper;
import com.xyht.sca_s.student_manage_system.modules.student.mapper.SmsUserStudentRelationMapper;
import com.xyht.sca_s.student_manage_system.modules.user.entity.SmsUser;
import com.xyht.sca_s.student_manage_system.modules.user.mapper.SmsUserMapper;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.constant.ChargePlanConstant;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.entity.SmsWnsChargeCategory;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.entity.SmsWnsChargeCategoryDetail;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.entity.SmsWnsChargePlan;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.entity.SmsWnsChargePlanStudentStatus;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.entity.req.OfflineRefundReq;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.entity.resp.ListCategoryDetailResp;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.entity.resp.SmsWnsChargePlanResp;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.entity.resp.SmsWnsChargePlanStudentStatusResp;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.mapper.SmsWnsChargeCategoryDetailMapper;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.mapper.SmsWnsChargeCategoryMapper;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.mapper.SmsWnsChargePlanMapper;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.mapper.SmsWnsChargePlanStudentStatusMapper;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.util.AssistantUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import static com.xyht.sca_s.student_manage_system.common.util.ParamCheckUtil.isLegalDateRange;
import static com.xyht.sca_s.student_manage_system.common.util.ParamCheckUtil.isNullOrEmpty;
import static com.xyht.sca_s.student_manage_system.modules.chargePayment.constant.SmsWnsChargePaymentRecordConstant.*;

/**
 * <p>
 * 缴费记录表 服务实现类
 * </p>
 *
 * @author XYHT
 * @since 2024-02-05
 */
@Service
@Slf4j
public class SmsWnsChargePaymentRecordServiceImpl extends ServiceImpl<SmsWnsChargePaymentRecordMapper, SmsWnsChargePaymentRecord> implements SmsWnsChargePaymentRecordService {

    @Resource
    private SmsWnsChargePlanMapper smsWnsChargePlanMapper;
    @Resource
    private SmsWnsChargeCategoryDetailMapper smsWnsChargeCategoryDetailMapper;
    @Resource
    private WxPayUtil wxPayUtil;
    @Resource
    private SmsUserMapper smsUserMapper;
    @Resource
    private SmsWnsChargePlanStudentStatusMapper smsWnsChargePlanStudentStatusMapper;
    @Resource
    private SmsWnsChargePaymentCategoryDivideMapper smsWnsChargePaymentCategoryDivideMapper;
    @Resource
    private SmsEnrollmentManagementStudentInfoMapper smsEnrollmentManagementStudentInfoMapper;
    @Resource
    private SmsWnsChargePaymentRecordMapper smsWnsChargePaymentRecordMapper;
    @Resource
    private AssistantUtil assistantUtil;
    @Resource
    private SmsStudentInfoMapper smsStudentInfoMapper;
    @Resource
    private SmsUserStudentRelationMapper smsUserStudentRelationMapper;
    @Resource
    private OrgUserStuUtil orgUserStuUtil;
    @Resource
    private SmsWnsChargeCategoryMapper smsWnsChargeCategoryMapper;
    @Resource
    private RxAdvanceRegistrationStudentInfoMapper rxAdvanceRegistrationStudentInfoMapper;

    @Override
    public ResponseResult listPlanNeedPay(Integer pageNum, Integer pageSize, String userId) {
        // 方案一
//        StuOrgInfoResp stuOrgInfo = categoryItemUtil.getStuOrgInfoByUserId(userId);
//        if (stuOrgInfo == null) {
//            return CommonResult.failed(CommonCodeEnum.WNS_PLAN_STUDENT_ORG_INFO_MISSING);
//        }
//
//        List<SmsWnsChargePaymentRecord> paymentRecordList = this.list(new LambdaQueryWrapper<SmsWnsChargePaymentRecord>()
//                .eq(SmsWnsChargePaymentRecord::getType, ChargePlanConstant.CHARGE_PLAN_TYPE_COMMON) // 普通缴费
//                .eq(SmsWnsChargePaymentRecord::getUserId, userId)
//                .eq(SmsWnsChargePaymentRecord::getStuId, stuOrgInfo.getStuId())
//                .isNotNull(SmsWnsChargePaymentRecord::getPaymentAmount));
//        List<String> isPaidPlanIdList = paymentRecordList.stream().map(SmsWnsChargePaymentRecord::getEventId).collect(Collectors.toList());
//
//        Date nowDate = new Date();
//        LambdaQueryWrapper<SmsWnsChargePlan> queryWrapper = new LambdaQueryWrapper<SmsWnsChargePlan>()
//                .eq(SmsWnsChargePlan::getType, ChargePlanConstant.CHARGE_PLAN_TYPE_COMMON) // 普通缴费
//                .le(SmsWnsChargePlan::getStartTime, nowDate)
//                .ge(SmsWnsChargePlan::getEndTime, nowDate)
//                .notIn(!isPaidPlanIdList.isEmpty(), SmsWnsChargePlan::getId, isPaidPlanIdList)
//                .orderByDesc(SmsWnsChargePlan::getCreateTime);
//
//        // 获取属于自己的计划
//        List<SmsWnsChargePlan> planList = smsWnsChargePlanMapper.selectList(queryWrapper);
//        List<SmsWnsChargePlan> planNeedPayList = new ArrayList<>();
//        for (SmsWnsChargePlan plan : planList) {
//            List<String> idList = JSON.parseArray(plan.getIdList(), String.class);
//            boolean flag = false;
//
//            if (plan.getRangeType() == ChargePlanConstant.CHARGE_PLAN_RANGE_TYPE_MAJOR) {
//                if (stuOrgInfo.getGradeName().equals(plan.getGrade()) && idList.contains(stuOrgInfo.getMajorId())) {
//                    flag = true;
//                }
//            } else if (plan.getRangeType() == ChargePlanConstant.CHARGE_PLAN_RANGE_TYPE_CLASS) {
//                if (idList.contains(stuOrgInfo.getClassId())) {
//                    flag = true;
//                }
//            } else if (plan.getRangeType() == ChargePlanConstant.CHARGE_PLAN_RANGE_TYPE_USER) {
//                if (idList.contains(stuOrgInfo.getStuId())) {
//                    flag = true;
//                }
//            }
//
//            if (flag) {
//                planNeedPayList.add(plan);
//            }
//        }
//
//        List<String> planNeedPayIdList = planNeedPayList.stream().map(SmsWnsChargePlan::getId).collect(Collectors.toList());
//        if (!planNeedPayIdList.isEmpty()) {
//            queryWrapper.in(SmsWnsChargePlan::getId, planNeedPayIdList);
//        } else {
//            queryWrapper.in(SmsWnsChargePlan::getId, "");
//        }
//
//        Page<SmsWnsChargePlan> page = new Page<>(pageNum, pageSize);
//        smsWnsChargePlanMapper.selectPage(page, queryWrapper);
//
//        List<SmsWnsChargePlanResp> planRespList = page.getRecords().stream().map(plan -> {
//            SmsWnsChargePlanResp planResp = new SmsWnsChargePlanResp();
//            BeanUtils.copyProperties(plan, planResp);
//
//            return planResp;
//        }).collect(Collectors.toList());

        // 方案二
        List<SmsWnsChargePlanStudentStatus> studentStatusList = smsWnsChargePlanStudentStatusMapper.selectList(new LambdaQueryWrapper<SmsWnsChargePlanStudentStatus>()
                .eq(SmsWnsChargePlanStudentStatus::getUserId, userId)
                .eq(SmsWnsChargePlanStudentStatus::getIsNecessary, true) // 选择此项
                .eq(SmsWnsChargePlanStudentStatus::getIsPaid, false)); // 未交齐

        // 收集planIdList
        List<String> planIdList = studentStatusList.stream().map(SmsWnsChargePlanStudentStatus::getPlanId).distinct().collect(Collectors.toList());

        // 查询还未选择收费项的计划
        List<String> notChooseStatusPlanIdList = smsWnsChargePlanStudentStatusMapper.listPlanIdNotChooseStatus(userId);
        if (!notChooseStatusPlanIdList.isEmpty()) {
            planIdList.addAll(notChooseStatusPlanIdList);
        }

        Page<SmsWnsChargePlan> page = new Page<>(pageNum, pageSize);
        Date nowDate = new Date();
        LambdaQueryWrapper<SmsWnsChargePlan> queryWrapper = new LambdaQueryWrapper<SmsWnsChargePlan>()
                .eq(SmsWnsChargePlan::getType, ChargePlanConstant.CHARGE_PLAN_TYPE_COMMON) // 普通缴费
                .eq(SmsWnsChargePlan::getIsPublish, true)
                .le(SmsWnsChargePlan::getStartTime, nowDate)
                .ge(SmsWnsChargePlan::getEndTime, nowDate)
                .orderByDesc(SmsWnsChargePlan::getStartTime);

        queryWrapper.in(SmsWnsChargePlan::getId, planIdList.isEmpty() ? Collections.singletonList("") : planIdList);
        smsWnsChargePlanMapper.selectPage(page, queryWrapper);

        List<SmsWnsChargePlanResp> planRespList = page.getRecords().stream().map(plan -> {
            SmsWnsChargePlanResp planResp = new SmsWnsChargePlanResp();
            BeanUtils.copyProperties(plan, planResp);

            return planResp;
        }).collect(Collectors.toList());

        return CommonResult.success(planRespList, (int) page.getTotal());
    }

    @Override
    public ResponseResult listPaidPlan(Integer pageNum, Integer pageSize, String userId) {
        List<SmsWnsChargePlanStudentStatus> studentStatusList = smsWnsChargePlanStudentStatusMapper.selectList(new LambdaQueryWrapper<SmsWnsChargePlanStudentStatus>()
                .eq(SmsWnsChargePlanStudentStatus::getUserId, userId)
                .isNotNull(SmsWnsChargePlanStudentStatus::getPaymentAmount)); // 交过钱

        List<String> planIdList = studentStatusList.stream().map(SmsWnsChargePlanStudentStatus::getPlanId).distinct().collect(Collectors.toList());
        Page<SmsWnsChargePlan> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<SmsWnsChargePlan> queryWrapper = new LambdaQueryWrapper<SmsWnsChargePlan>()
                .eq(SmsWnsChargePlan::getType, ChargePlanConstant.CHARGE_PLAN_TYPE_COMMON) // 普通缴费
                .eq(SmsWnsChargePlan::getIsPublish, true)
                .orderByDesc(SmsWnsChargePlan::getStartTime);
        if (planIdList.isEmpty()) {
            queryWrapper.in(SmsWnsChargePlan::getId, "");
        } else {
            queryWrapper.in(SmsWnsChargePlan::getId, planIdList);
        }
        smsWnsChargePlanMapper.selectPage(page, queryWrapper);

        List<SmsWnsChargePlanResp> planRespList = page.getRecords().stream().map(plan -> {
            SmsWnsChargePlanResp planResp = new SmsWnsChargePlanResp();
            BeanUtils.copyProperties(plan, planResp);

            return planResp;
        }).collect(Collectors.toList());
        return CommonResult.success(planRespList, (int) page.getTotal());
    }

    @Override
    public ResponseResult listPaymentRecord(Integer pageNum, Integer pageSize, String userId) {
        LambdaQueryWrapper<SmsWnsChargePaymentRecord> queryWrapper = new LambdaQueryWrapper<SmsWnsChargePaymentRecord>()
                .eq(SmsWnsChargePaymentRecord::getUserId, userId)
                .isNotNull(SmsWnsChargePaymentRecord::getPaymentAmount)
                .orderByDesc(SmsWnsChargePaymentRecord::getCreateTime);

        Page<SmsWnsChargePaymentRecord> page = new Page<>(pageNum, pageSize);
        this.page(page, queryWrapper);
        List<SmsWnsChargePaymentRecordResp> paymentRecordRespList = page.getRecords().stream().map(paymentRecord -> {
            SmsWnsChargePaymentRecordResp paymentRecordResp = new SmsWnsChargePaymentRecordResp();
            BeanUtils.copyProperties(paymentRecord, paymentRecordResp);

            SmsWnsChargePlan plan = smsWnsChargePlanMapper.selectById(paymentRecord.getEventId());
            if (plan != null) {
                paymentRecordResp.setPlanName(plan.getName());
            }

            return paymentRecordResp;
        }).collect(Collectors.toList());

        return CommonResult.success(paymentRecordRespList, (int) page.getTotal());
    }

    @Override
    public ResponseResult listCategoryDetail(String planId, String userId) {
//        SmsWnsChargePlan plan = smsWnsChargePlanMapper.selectById(planId);
//        if (plan == null) {
//            return CommonResult.failed(CommonCodeEnum.WNS_CHARGE_PLAN_NOT_EXIST);
//        }
//
//        if (isNullOrEmpty(plan.getDetailIdList())) {
//            return CommonResult.failed(CommonCodeEnum.WNS_CHARGE_PLAN_DETAIL_LIST_NOT_EXIST);
//        }
//
//        StuOrgInfoResp stuOrgInfo = categoryItemUtil.getStuOrgInfoByUserId(userId);
//        if (stuOrgInfo == null) {
//            return CommonResult.failed(CommonCodeEnum.WNS_PLAN_STUDENT_ORG_INFO_MISSING);
//        }
//
//        // 查询收费项
//        LambdaQueryWrapper<SmsWnsChargeOrgItem> queryWrapper = new LambdaQueryWrapper<SmsWnsChargeOrgItem>()
//                .eq(SmsWnsChargeOrgItem::getPlanId, planId);
//        if (plan.getRangeType() == ChargePlanConstant.CHARGE_PLAN_RANGE_TYPE_MAJOR) {
//            queryWrapper.eq(SmsWnsChargeOrgItem::getOrgId, stuOrgInfo.getMajorId());
//        } else if (plan.getRangeType() == ChargePlanConstant.CHARGE_PLAN_RANGE_TYPE_CLASS) {
//            queryWrapper.eq(SmsWnsChargeOrgItem::getOrgId, stuOrgInfo.getClassId());
//        } else if (plan.getRangeType() != ChargePlanConstant.CHARGE_PLAN_RANGE_TYPE_USER) {
//            queryWrapper.eq(SmsWnsChargeOrgItem::getOrgId, stuOrgInfo.getStuId());
//        }
//
//        List<SmsWnsChargeOrgItem> smsWnsChargeOrgItemList = smsWnsChargeOrgItemMapper.selectList(queryWrapper);
//        BigDecimal totalAmount = new BigDecimal(0);
//        List<SmsWnsChargeOrgItemResp> itemRespList = new ArrayList<>();
//        List<String> detailIdList = JSON.parseArray(plan.getDetailIdList(), String.class);
//        List<SmsWnsChargeCategoryDetail> detailList = smsWnsChargeCategoryDetailMapper.selectBatchIds(detailIdList);
//        for (SmsWnsChargeOrgItem item : smsWnsChargeOrgItemList) {
//            SmsWnsChargeOrgItemResp itemResp = new SmsWnsChargeOrgItemResp();
//            BeanUtils.copyProperties(item, itemResp);
//            List<SmsWnsChargeCategoryDetail> filterDetailList = detailList.stream().filter(detail -> detail.getId().equals(item.getCategoryDetailId())).collect(Collectors.toList());
//            itemResp.setCategoryDetailName(filterDetailList.get(0).getName());
//
//            itemRespList.add(itemResp);
//            totalAmount = totalAmount.add(item.getAmount());
//        }
//
//        ListCategoryDetailResp listCategoryDetailResp = new ListCategoryDetailResp();
//        listCategoryDetailResp.setItemRespList(itemRespList);
//        listCategoryDetailResp.setAmount(totalAmount);

        // 方案二
        SmsWnsChargePlan plan = smsWnsChargePlanMapper.selectById(planId);
        if (plan == null) {
            return CommonResult.failed(CommonCodeEnum.WNS_CHARGE_PLAN_NOT_EXIST);
        }

        if (isNullOrEmpty(plan.getDetailIdList())) {
            return CommonResult.failed(CommonCodeEnum.WNS_CHARGE_PLAN_DETAIL_LIST_NOT_EXIST);
        }

        List<SmsWnsChargePlanStudentStatus> studentStatusList = smsWnsChargePlanStudentStatusMapper.selectList(new LambdaQueryWrapper<SmsWnsChargePlanStudentStatus>()
                .eq(SmsWnsChargePlanStudentStatus::getPlanId, planId)
                .eq(SmsWnsChargePlanStudentStatus::getUserId, userId));
        if (studentStatusList.isEmpty()) {
            return CommonResult.failed(CommonCodeEnum.WNS_PLAN_STUDENT_STATUS_MISSING);
        }

        // 计算应缴总金额
        BigDecimal totalAmount = new BigDecimal(0);

        // 获取所有收费项
        List<String> detailIdList = JSON.parseArray(plan.getDetailIdList(), String.class);
        List<SmsWnsChargeCategoryDetail> detailList = smsWnsChargeCategoryDetailMapper.selectBatchIds(detailIdList);

        // 构造返回数据
        List<SmsWnsChargePlanStudentStatusResp> studentStatusRespList = new ArrayList<>();
        for (SmsWnsChargePlanStudentStatus studentStatus : studentStatusList) {
            SmsWnsChargePlanStudentStatusResp studentStatusResp = new SmsWnsChargePlanStudentStatusResp();
            BeanUtils.copyProperties(studentStatus, studentStatusResp);

            // 设置分类详情名
            List<SmsWnsChargeCategoryDetail> filterDetailList = detailList.stream().filter(detail -> detail.getId().equals(studentStatus.getCategoryDetailId())).collect(Collectors.toList());
            studentStatusResp.setCategoryDetailName(filterDetailList.get(0).getName());

            studentStatusRespList.add(studentStatusResp);

            // 计算该项还需缴纳金额 = 总金额 + 欠费金额
            totalAmount = totalAmount.add(studentStatus.getNeedPaymentAmount());
        }

        ListCategoryDetailResp listCategoryDetailResp = new ListCategoryDetailResp();
        listCategoryDetailResp.setStudentStatusRespList(studentStatusRespList);
        listCategoryDetailResp.setTotalAmount(totalAmount);
        listCategoryDetailResp.setStartTime(plan.getStartTime());
        listCategoryDetailResp.setEndTime(plan.getEndTime());

        return CommonResult.success(listCategoryDetailResp);
    }

    @Override
    @Transactional
    public ResponseResult payment(SmsWnsChargePaymentRecordReq recordReq, String userId) {
        if (isNullOrEmpty(recordReq.getType())) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }

        // 校验用户及wxOpenId是否存在
        SmsUser user = smsUserMapper.selectById(userId);
        if (user == null || isNullOrEmpty(user.getWxId())) {
            return CommonResult.failed(CommonCodeEnum.FAIL);
        }

        // 声明公共数据
        BigDecimal totalAmount = new BigDecimal(0); // 付款总金额
        String description = null; // 商品描述
        Date timeExpire = TimeUtil.AddMinute(new Date(), 30); // 设置过期时间(订单失效时间)
        SmsWnsChargePaymentRecord paymentRecord = new SmsWnsChargePaymentRecord(); // 新生成的支付记录
        // 设置过期时间 = 当前时间 + 30min
        paymentRecord.setExpireTime(timeExpire);
        if (recordReq.getType() == CHARGE_PAYMENT_RECORD_TYPE_NEW_STUDENT || recordReq.getType() == CHARGE_PAYMENT_RECORD_TYPE_COMMON) { // 新生缴费或普通缴费
            // 校验各项分配金额
            if (recordReq.getDivideReqList().isEmpty()) {
                return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
            }

            // 获取各收费项
            List<String> statusIdList = recordReq.getDivideReqList().stream().map(PaymentCategoryDivideReq::getStudentStatusId).collect(Collectors.toList());
            List<SmsWnsChargePlanStudentStatus> statusList = smsWnsChargePlanStudentStatusMapper.selectBatchIds(statusIdList);
            if (statusList.size() != statusIdList.size()) {
                return CommonResult.failed(CommonCodeEnum.WNS_PLAN_STUDENT_STATUS_MISSING);
            }

            // 校验是否属于同一个计划
            List<String> planIdList = statusList.stream().map(SmsWnsChargePlanStudentStatus::getPlanId).distinct().collect(Collectors.toList());
            if (planIdList.size() != 1) {
                return CommonResult.failed(CommonCodeEnum.WNS_PLAN_STUDENT_STATUS_NOT_BELONG_SAME_PLAN);
            }

            // 校验计划是否存在
            String planId = planIdList.get(0);
            SmsWnsChargePlan plan = smsWnsChargePlanMapper.selectById(planId);
            if (plan == null || !plan.getIsPublish()) { // 计划不存在或未发布
                return CommonResult.failed(CommonCodeEnum.WNS_CHARGE_PLAN_NOT_EXIST);
            }

            // 设置商户类型
            recordReq.setWxPayFunctionType(plan.getWxPayFunctionType());

            // 校验计划是否已暂停
            if (plan.getIsPause()) {
                return CommonResult.failed(CommonCodeEnum.WNS_CHARGE_PLAN_PAUSE);
            }

            // 生成支付记录
            paymentRecord.setType(plan.getType());
            paymentRecord.setMode(CHARGE_PAYMENT_RECORD_MODE_ONLINE);
            paymentRecord.setEventId(plan.getId());
            paymentRecord.setUserId(userId);
            this.save(paymentRecord);
            if (isNullOrEmpty(paymentRecord.getId())) {
                return CommonResult.failed(CommonCodeEnum.WNS_PAYMENT_RECORD_SAVE_FAIL);
            }

            // 移除无效数据(超过半小时未支付)
            List<SmsWnsChargePaymentRecord> ivalidPaymentRecordList = this.list(new LambdaQueryWrapper<SmsWnsChargePaymentRecord>()
                    .eq(SmsWnsChargePaymentRecord::getEventId, planId)
                    .eq(SmsWnsChargePaymentRecord::getUserId, userId)
                    .le(SmsWnsChargePaymentRecord::getExpireTime, new Date())
                    .isNull(SmsWnsChargePaymentRecord::getPaymentTime));
            if (!ivalidPaymentRecordList.isEmpty()) {
                List<String> ivalidPaymentRecordIdList = ivalidPaymentRecordList.stream().map(SmsWnsChargePaymentRecord::getId).distinct().collect(Collectors.toList());
                this.removeByIds(ivalidPaymentRecordIdList);
                smsWnsChargePaymentCategoryDivideMapper.delete(new LambdaQueryWrapper<SmsWnsChargePaymentCategoryDivide>()
                        .in(SmsWnsChargePaymentCategoryDivide::getPaymentRecordId, ivalidPaymentRecordIdList));
            }

            // 统计用户缴费总金额
            for (PaymentCategoryDivideReq divideReq : recordReq.getDivideReqList()) {
                // 获取对应的收费项
                SmsWnsChargePlanStudentStatus studentStatus = statusList.stream().filter(status -> status.getId().equals(divideReq.getStudentStatusId())).collect(Collectors.toList()).get(0);
                // 校验之前是否选择本项,未选择则修改本项
                if (!studentStatus.getIsNecessary()) {
                    studentStatus.setIsNecessary(true); // 选择此项
                    smsWnsChargePlanStudentStatusMapper.updateById(studentStatus);
                }

                // 校验分配金额
                if (divideReq.getAmount() == null // 分配金额为空
                        || divideReq.getAmount().compareTo(BigDecimal.valueOf(0)) < 0 // 分配金额小于0
                        || divideReq.getAmount().compareTo(studentStatus.getNeedPaymentAmount()) > 0) { // 分配金额 > 欠费金额
                    ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.WNS_PAYMENT_DIVIDE_AMOUNT_ILLEGAL));
                }

                // 生成金额分配数据
                SmsWnsChargePaymentCategoryDivide categoryDivide = new SmsWnsChargePaymentCategoryDivide();
                categoryDivide.setPaymentRecordId(paymentRecord.getId());
                categoryDivide.setPlanId(planId);
                categoryDivide.setUserId(userId);
                categoryDivide.setCategoryId(studentStatus.getCategoryId());
                categoryDivide.setCategoryDetailId(studentStatus.getCategoryDetailId());
                categoryDivide.setChargeItemId(studentStatus.getChargeItemId());
                categoryDivide.setAmount(divideReq.getAmount());
                smsWnsChargePaymentCategoryDivideMapper.insert(categoryDivide);

                totalAmount = totalAmount.add(divideReq.getAmount());
//            log.info("totalAmount------------------:{}", totalAmount);
            }

            if (plan.getType() == ChargePlanConstant.CHARGE_PLAN_TYPE_NEW_STUDENT) { // 新生缴费
                // 设置商品描述:新生缴费
                description = CHARGE_PAYMENT_RECORD_TYPE_DES_NEW_STUDENT;
            } else if (plan.getType() == ChargePlanConstant.CHARGE_PLAN_TYPE_COMMON) { // 普通缴费
                // 设置商品描述:普通缴费
                description = CHARGE_PAYMENT_RECORD_TYPE_DES_COMMON;
            }
        } else if (recordReq.getType() == CHARGE_PAYMENT_RECORD_NEW_STU_PREPAY) { // 招生预支付
            // 设置商品描述:招生预支付
            description = CHARGE_PAYMENT_RECORD_TYPE_DES_NEW_STU_PREPAY;

            // TODO 保存支付记录(paymentRecord),统计用户缴费总金额(totalAmount)

            return CommonResult.failed(CommonCodeEnum.FAIL);
        }

        // 发起支付
        PrepayPaymentReq prepayPaymentReq = new PrepayPaymentReq();
        prepayPaymentReq.setDescription(description);
        prepayPaymentReq.setOutTradeNo(paymentRecord.getId());
        prepayPaymentReq.setTimeExpire(timeExpire);
        // 设置订单金额 单位：分(订单金额 = 原金额(元) * 100)
        int total = totalAmount.multiply(BigDecimal.valueOf(100)).intValue();
        prepayPaymentReq.setTotal(total);
        prepayPaymentReq.setOpenId(user.getWxId());

        // 获取商户集合
        List<WxPayFunctions> wxPayFunctionsList = WxPayConfig.wxPayFunctionsList;
        if (wxPayFunctionsList.isEmpty()) {
            ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.FAIL));
        }
        // 校验前端传入的商户Type
        if (recordReq.getWxPayFunctionType() == null || recordReq.getWxPayFunctionType() <= 0
                || recordReq.getWxPayFunctionType() > wxPayFunctionsList.size() + 1) {
            ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.INVALID_PARAM));
        }
        // 获取用户选择的商户
        WxPayFunctions wxPayFunction = wxPayFunctionsList.get(recordReq.getWxPayFunctionType() - 1);
        // 发起支付
        PrepayWithRequestPaymentResponse prepayWithRequestPaymentResponse = wxPayUtil.prepayPayment(prepayPaymentReq, wxPayFunction);
        if (prepayWithRequestPaymentResponse == null) {
            ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.WNS_PAYMENT_PRE_PAYMENT_INFO_MISSING));
        }
//        log.info(prepayWithRequestPaymentResponse.toString());

        // 构造返回数据
        SmsWnsChargePaymentRecordResp paymentRecordResp = new SmsWnsChargePaymentRecordResp();
        BeanUtils.copyProperties(paymentRecord, paymentRecordResp);
        // 设置预支付信息
        PrepayPaymentResp prepayPaymentResp = new PrepayPaymentResp();
        BeanUtils.copyProperties(prepayWithRequestPaymentResponse, prepayPaymentResp);
        prepayPaymentResp.setTimestamp(prepayWithRequestPaymentResponse.getTimeStamp());
        paymentRecordResp.setPrepayPaymentResp(prepayPaymentResp);
//        log.info(prepayPaymentResp.toString());

        // 记录预支付数据
        paymentRecord.setPrepayId(JSON.toJSONString(prepayPaymentResp));
        paymentRecord.setConfigName(wxPayFunction.getWxPayCommonConfig().getCONFIG_NAME());
        this.updateById(paymentRecord);

        return CommonResult.success(paymentRecordResp);
    }

    @Override
    public ResponseResult getStudentPaymentRecord(Integer pageNum, Integer pageSize, String stuName, Integer type) {
        Page<SmsWnsChargePaymentRecord> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<SmsWnsChargePaymentRecord> chargePaymentRecordLambdaQueryWrapper = new LambdaQueryWrapper<SmsWnsChargePaymentRecord>()
                .isNotNull(SmsWnsChargePaymentRecord::getPaymentAmount)
                .orderByDesc(SmsWnsChargePaymentRecord::getCreateTime);
        if (!isNullOrEmpty(type)) {
            chargePaymentRecordLambdaQueryWrapper.eq(SmsWnsChargePaymentRecord::getType, type);
        }
        if (!isNullOrEmpty(stuName)) {
            //普通缴费
//            List<String> userIdList = smsUserMapper.selectList(new LambdaQueryWrapper<SmsUser>()
//                    .like(SmsUser::getRealName, stuName)).stream().map(SmsUser::getId).collect(Collectors.toList());

            List<String> stuIdLIst = orgUserStuUtil.getStuIdListBySearchStr(stuName);
            List<String> userIdList = orgUserStuUtil.getUserIdListByStuIdList(stuIdLIst);

            //招生预支付
            List<String> enrollmentManagementStudentIdList = smsEnrollmentManagementStudentInfoMapper.selectList(new LambdaQueryWrapper<SmsEnrollmentManagementStudentInfo>()
                    .like(SmsEnrollmentManagementStudentInfo::getStudentName, stuName)).stream().map(SmsEnrollmentManagementStudentInfo::getId).collect(Collectors.toList());
            chargePaymentRecordLambdaQueryWrapper.and(i -> {
                if (!userIdList.isEmpty()) {
                    i.in(SmsWnsChargePaymentRecord::getUserId, userIdList);
                } else {
                    i.in(SmsWnsChargePaymentRecord::getUserId, "");
                }
                i.or();
                if (!enrollmentManagementStudentIdList.isEmpty()) {
                    i.in(SmsWnsChargePaymentRecord::getEventId, enrollmentManagementStudentIdList);
                } else {
                    i.in(SmsWnsChargePaymentRecord::getEventId, "");
                }
            });
        }
        smsWnsChargePaymentRecordMapper.selectPage(page, chargePaymentRecordLambdaQueryWrapper);
        List<SmsStudentPaymentRecordResp> records = page.getRecords()
                .stream()
                .map(smsWnsChargePaymentRecord -> {
                    SmsStudentPaymentRecordResp smsStudentPaymentRecordResp = new SmsStudentPaymentRecordResp();
                    SmsStudentInfoResp studentInfo = new SmsStudentInfoResp();
                    //学生信息
                    SmsUserStudentRelation smsUserStudentRelation = smsUserStudentRelationMapper.selectOne(new LambdaQueryWrapper<SmsUserStudentRelation>()
                            .eq(SmsUserStudentRelation::getUserId, smsWnsChargePaymentRecord.getUserId()));
                    if (!isNullOrEmpty(smsUserStudentRelation)) {
                        BeanUtils.copyProperties(smsWnsChargePaymentRecord, smsStudentPaymentRecordResp);
                        smsStudentPaymentRecordResp.setRecordId(smsWnsChargePaymentRecord.getId());
                        String stuId = smsUserStudentRelation.getStuId();
                        SmsStudentInfo smsStudentInfo = smsStudentInfoMapper.selectById(stuId);
                        if (!isNullOrEmpty(smsStudentInfo)) {
                            BeanUtils.copyProperties(smsStudentInfo, studentInfo);
                            smsStudentPaymentRecordResp.setStudentInfo(studentInfo);
                        }
                        //辅导员
                        List<SmsUser> assistantInfo = assistantUtil.getAssistantByUserId(smsWnsChargePaymentRecord.getUserId());
                        if (assistantInfo != null && assistantInfo.size() > 0) {
                            smsStudentPaymentRecordResp.setAssistantInfo(assistantInfo.get(0));
                        }
                    }
                    return smsStudentPaymentRecordResp;
                })
                .collect(Collectors.toList());

        return CommonResult.success(records, (int) page.getTotal());
    }

    @Override
    public ResponseResult getStudentPaymentRecordDetail(Integer pageNum, Integer pageSize, String stuName, String recordId) {
        if (isNullOrEmpty(recordId)) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }
        Page<SmsWnsChargePaymentCategoryDivide> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<SmsWnsChargePaymentCategoryDivide> categoryDivideLambdaQueryWrapper = new LambdaQueryWrapper<SmsWnsChargePaymentCategoryDivide>()
                .orderByDesc(SmsWnsChargePaymentCategoryDivide::getCreateTime);
        if (!isNullOrEmpty(stuName)) {
            //普通缴费
            List<String> userIdList = smsUserMapper.selectList(new LambdaQueryWrapper<SmsUser>()
                    .like(SmsUser::getRealName, stuName)).stream().map(SmsUser::getId).collect(Collectors.toList());
            if (!userIdList.isEmpty()) {
                categoryDivideLambdaQueryWrapper.in(SmsWnsChargePaymentCategoryDivide::getUserId, userIdList);
            } else {
                categoryDivideLambdaQueryWrapper.in(SmsWnsChargePaymentCategoryDivide::getUserId, "");
            }
        }
        List<SmsStudentPaymentRecordDetailResp> paymentCategoryDetailList = smsWnsChargePaymentCategoryDivideMapper.selectList(categoryDivideLambdaQueryWrapper
                        .eq(SmsWnsChargePaymentCategoryDivide::getPaymentRecordId, recordId))
                .stream()
                .map(smsWnsChargePaymentCategoryDivide -> {
                    SmsStudentPaymentRecordDetailResp smsStudentPaymentRecordDetailResp = new SmsStudentPaymentRecordDetailResp();
                    //收费项
                    SmsWnsChargeCategoryDetail smsWnsChargeCategoryDetail = smsWnsChargeCategoryDetailMapper.selectAllById(smsWnsChargePaymentCategoryDivide.getCategoryDetailId());
                    if (!isNullOrEmpty(smsWnsChargeCategoryDetail)) {
                        BeanUtils.copyProperties(smsWnsChargePaymentCategoryDivide, smsStudentPaymentRecordDetailResp);
                        smsStudentPaymentRecordDetailResp.setCategoryDetailId(smsWnsChargeCategoryDetail.getId());
                        smsStudentPaymentRecordDetailResp.setCategoryDetailName(smsWnsChargeCategoryDetail.getName());
                    }
                    return smsStudentPaymentRecordDetailResp;
                })
                .collect(Collectors.toList());

        return CommonResult.success(paymentCategoryDetailList, (int) page.getTotal());
    }

    @Override
    public ResponseResult paymentFlow(Integer pageNum, Integer pageSize, Integer type, Integer mode, Integer orgId, Date startTime, Date endTime, String searchStr) {
        LambdaQueryWrapper<SmsWnsChargePaymentRecord> queryWrapper = new LambdaQueryWrapper<SmsWnsChargePaymentRecord>()
                .isNotNull(SmsWnsChargePaymentRecord::getPaymentAmount)
                .orderByDesc(SmsWnsChargePaymentRecord::getPaymentAmount);

        // 缴费来源(0.新生缴费 1.普通缴费 2.招生预支付)
        if (type != null) {
            queryWrapper.eq(SmsWnsChargePaymentRecord::getType, type);
        }

        // 流水类型(0.线上缴费 1.线下缴费 2.助学贷款核销 3.退费)
        if (mode != null) {
            queryWrapper.eq(SmsWnsChargePaymentRecord::getMode, mode);
        }

        // 组织id
        if (orgId != null) {
            List<String> userIdList = orgUserStuUtil.getUserIdListByOrgId(orgId);
            queryWrapper.in(SmsWnsChargePaymentRecord::getUserId, userIdList.isEmpty() ? Collections.singletonList("") : userIdList);
        }

        // 时间范围
        if (isLegalDateRange(startTime, endTime)) {
            queryWrapper.between(SmsWnsChargePaymentRecord::getCreateTime, startTime, endTime);
        }

        // 模糊查询字符串(查询符合条件的stuIdList)
        if (!isNullOrEmpty(searchStr)) {
            List<String> stuIdList = orgUserStuUtil.getStuIdListBySearchStr(searchStr);
            queryWrapper.in(SmsWnsChargePaymentRecord::getStuId, stuIdList.isEmpty() ? Collections.singletonList("") : stuIdList);
        }

        Page<SmsWnsChargePaymentRecord> page = new Page<>(pageNum, pageSize);
        this.page(page, queryWrapper);
        List<StudentPaymentFlowResp> collect = page.getRecords().stream().map(paymentRecord -> {
            StudentPaymentFlowResp studentPaymentFlowResp = new StudentPaymentFlowResp();
            BeanUtils.copyProperties(paymentRecord, studentPaymentFlowResp);

            // 设置学生信息
            String stuId;
            if (paymentRecord.getType() == CHARGE_PAYMENT_RECORD_NEW_STU_PREPAY) { //预报名学生信息
                stuId = paymentRecord.getEventId();
                if (!isNullOrEmpty(stuId)) {
                    RxAdvanceRegistrationStudentInfo rxAdvanceRegistrationStudentInfo = rxAdvanceRegistrationStudentInfoMapper.selectById(stuId);
                    if (rxAdvanceRegistrationStudentInfo != null) {
                        SmsStudentInfo studentInfo = new SmsStudentInfo();
                        studentInfo.setStuName(rxAdvanceRegistrationStudentInfo.getName());
                        studentInfo.setStuSex(rxAdvanceRegistrationStudentInfo.getSex());
                        studentInfo.setStuIdCard(rxAdvanceRegistrationStudentInfo.getIdCard());
                        studentInfo.setStuTel(rxAdvanceRegistrationStudentInfo.getTel());
                        studentPaymentFlowResp.setStudentInfo(studentInfo);
                    }
                }
            }else {
                if (!isNullOrEmpty(paymentRecord.getStuId())) {
                    stuId = paymentRecord.getStuId();
                } else {
                    stuId = orgUserStuUtil.getStuIdByUserId(paymentRecord.getUserId());
                }
                if (stuId != null) {
                    SmsStudentInfo studentInfo = smsStudentInfoMapper.selectById(stuId);
                    if (studentInfo != null) {
                        studentPaymentFlowResp.setStudentInfo(studentInfo);
                    }
                }
            }



            // 设置计划信息
            if (paymentRecord.getType() == CHARGE_PAYMENT_RECORD_TYPE_NEW_STUDENT || paymentRecord.getType() == CHARGE_PAYMENT_RECORD_TYPE_COMMON) {
                SmsWnsChargePlan plan = smsWnsChargePlanMapper.selectAllById(paymentRecord.getEventId());
                if (plan != null) {
                    studentPaymentFlowResp.setPlan(plan);
                }


                // 设置该笔金额分配信息
                List<SmsWnsChargePaymentCategoryDivide> categoryDivideList = smsWnsChargePaymentCategoryDivideMapper.selectList(new LambdaQueryWrapper<SmsWnsChargePaymentCategoryDivide>()
                        .eq(SmsWnsChargePaymentCategoryDivide::getPaymentRecordId, paymentRecord.getId()));
                List<SmsWnsChargePaymentCategoryDivideResp> divideRespList = categoryDivideList.stream().map(categoryDivide -> {
                    SmsWnsChargePaymentCategoryDivideResp smsWnsChargePaymentCategoryDivideResp = new SmsWnsChargePaymentCategoryDivideResp();
                    BeanUtils.copyProperties(categoryDivide, smsWnsChargePaymentCategoryDivideResp);

                    // 设置分类名
                    SmsWnsChargeCategory category = smsWnsChargeCategoryMapper.selectAllById(categoryDivide.getCategoryId());
                    if (category != null) {
                        smsWnsChargePaymentCategoryDivideResp.setCategoryName(category.getName());
                    }

                    // 设置分类详情名
                    SmsWnsChargeCategoryDetail categoryDetail = smsWnsChargeCategoryDetailMapper.selectAllById(categoryDivide.getCategoryDetailId());
                    if (categoryDetail != null) {
                        smsWnsChargePaymentCategoryDivideResp.setCategoryDetailName(categoryDetail.getName());
                    }

                    return smsWnsChargePaymentCategoryDivideResp;
                }).collect(Collectors.toList());
                studentPaymentFlowResp.setDivideRespList(divideRespList);
            }

            return studentPaymentFlowResp;
        }).collect(Collectors.toList());

        return CommonResult.success(collect, (int) page.getTotal());
    }

    @Override
    @Transactional
    public ResponseResult removePlanOfflineRefund(OfflineRefundReq req) {
        if (isNullOrEmpty(req.getPlanId(), req.getStuId())) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }

        SmsWnsChargePlan plan = smsWnsChargePlanMapper.selectById(req.getPlanId());
        if (plan == null) {
            return CommonResult.failed(CommonCodeEnum.WNS_CHARGE_PLAN_NOT_EXIST);
        }

        String userId = orgUserStuUtil.getUserIdByStuId(req.getStuId());
        if (isNullOrEmpty(userId)) {
            return CommonResult.failed(CommonCodeEnum.USER_NOT_EXIST);
        }

        List<SmsWnsChargePlanStudentStatus> statusList = smsWnsChargePlanStudentStatusMapper.selectList(new LambdaQueryWrapper<SmsWnsChargePlanStudentStatus>()
                .eq(SmsWnsChargePlanStudentStatus::getPlanId, req.getPlanId())
                .eq(SmsWnsChargePlanStudentStatus::getUserId, userId));
        if (statusList.isEmpty()) {
            return CommonResult.failed(CommonCodeEnum.WNS_CHARGE_PLAN_RANGE_OUT_OF_TYPE);
        }

        // 统计应退金额
        BigDecimal totalDifference = statusList.stream()
                .map(s -> s.getTotalAmount().subtract(s.getNeedPaymentAmount()))
                .reduce(BigDecimal.ZERO, BigDecimal::add);

        // 如果有退费
        if (totalDifference.compareTo(BigDecimal.ZERO) != 0) {
            // 生成退费记录
            SmsWnsChargePaymentRecord paymentRecord = new SmsWnsChargePaymentRecord();
            paymentRecord.setType(plan.getType());
            paymentRecord.setMode(CHARGE_PAYMENT_RECORD_MODE_REFUND);
            paymentRecord.setEventId(req.getPlanId());
            paymentRecord.setUserId(userId);
            paymentRecord.setStuId(req.getStuId());
            paymentRecord.setPaymentAmount(totalDifference.negate());
            paymentRecord.setPaymentTime(new Date());
            paymentRecord.setNotes(CHARGE_PAYMENT_RECORD_TYPE_DES_REFUND);
            smsWnsChargePaymentRecordMapper.insert(paymentRecord);
        }

        // 将该学生移除本计划
        smsWnsChargePlanStudentStatusMapper.deleteBatchIds(
                statusList.stream().map(SmsWnsChargePlanStudentStatus::getId).collect(Collectors.toList()));

        return CommonResult.success();
    }

    @Override
    public ResponseResult paymentFlowStatistics(Integer type, Integer stepNum) {
        // 统计粒度(0.日 1.月 2.年)
        if (type == null || type < 0 || type > 2) {
            type = 0;
        }

        // 统计步数
        if (stepNum == null || stepNum < 0) {
            stepNum = 0;
        }

        // 默认步长为7
        int step = 7;

        // 根据粒度获取开始时间和结束时间
        Date startDate = TimeUtil.GetEndDate(new Date());
        Date endDate = TimeUtil.GetEndDate(new Date());
        int startOffset = -(stepNum + 1) * step;
        int endOffset = -stepNum * step;
        List<TimeAndAmountResp> timeAndAmountRespList = new ArrayList<>();
        switch (type) {
            case 0: // 日
                startDate = TimeUtil.AddDays(startDate, startOffset);
                endDate = TimeUtil.AddDays(endDate, endOffset);

                timeAndAmountRespList = smsWnsChargePaymentRecordMapper.getTimeAndAmountEveryDay(startDate, endDate);

                break;
            case 1: // 月
                startDate = TimeUtil.AddMonths(startDate, startOffset);
                endDate = TimeUtil.AddMonths(endDate, endOffset);

                timeAndAmountRespList = smsWnsChargePaymentRecordMapper.getTimeAndAmountEveryMonth(startDate, endDate);

                break;
            case 2: // 年
                startDate = TimeUtil.AddYears(startDate, startOffset);
                endDate = TimeUtil.AddYears(endDate, endOffset);

                timeAndAmountRespList = smsWnsChargePaymentRecordMapper.getTimeAndAmountEveryYear(startDate, endDate);

                break;
        }

        BigDecimal totalAmount = smsWnsChargePaymentRecordMapper.getTotalAmount(startDate, endDate);
        PaymentFlowStatisticsResp paymentFlowStatisticsResp = new PaymentFlowStatisticsResp();
        paymentFlowStatisticsResp.setTotalAmount(totalAmount);
        paymentFlowStatisticsResp.setTimeAndAmountRespList(timeAndAmountRespList);

        return CommonResult.success(paymentFlowStatisticsResp);
    }

}
